<!DOCTYPE html>
<html lang="en">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%
	String path = request.getContextPath(); 
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<head>
	<title>Moto - FGoods - 列表</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1,maximum-scale=1,user-scalable=no">
    <script type="text/javascript" src="../js/jquery-1.9.0.min.js"></script>
    <script type="text/javascript" src="../js/layer/layer.js"></script>
    <style type="text/css">
        .body_div{padding-top:2.2em;
            text-align:center;}
        .table-detail{
            text-align:center;
            border: 1px solid rgb(228,228,228);
        }
        th{
            text-align:center;
            background-color: rgb(230,230,230);
            border-bottom: 1px solid rgb(228,228,228);
            font-weight: bold;
            color:rgb(90,90,90);
            padding: 8px;
            width:50px;
        }
        td{
            text-align:center;
            border: 1px solid rgb(228,228,228);
            color:rgb(56,56,56);
            font-size:15px;
            padding: 8px;
            line-height: 1.5em;
            height:1.5em;
        }
        td input{
            width:90%;
        }
        ul li{
            border:solid 1px rgb(233,233,233) ;
            list-style :none;
            float:left;
            padding:8px 15px;
            line-height: 1.5em;
            height:1.5em;
        }
        a {
            text-decoration: none;
        }
    </style>
</head>

<body>
<form id="motoForm" name="motoForm" action="<%=basePath%>fgoods/list" method="post" >

<div class="body_div" >
    <table class="table-detail" style="overflow:hidden;margin:0 auto; width:1131px;" >
        <tr>
            <td nowrap="nowrap"><a href="javascript:ajaxAllUpFgoodsStatus();">[批量操作]</a></td>
            <th>状态</th>
            <td>
                <select id="status" name="status">
                    <option value="">全部</option>
                    <option value="0">未确认</option>
                    <option value="1">已确认</option>
                    <option value="-1">弃用</option>
                </select>
            </td>
            <th>名称</th>
            <td>
               <input type="text" name="goodsname" id="goodsname" value="${SRModel.goodsname}"/>
            </td>
            <th>主类</th>
            <td>
                <input type="text" name="goodstype" id="goodstype" value="${SRModel.goodstype}"/>
            </td>
            <th>子类</th>
            <td>
                <input type="text" name="goodstwotype" id="goodstwotype" value="${SRModel.goodstwotype}"/>
            </td>
            <td>
              <a href="javascript:searchData('1')">查询</a>
            </td>
            <td>
                <a href="javascript:clearFrom()">清空</a>
            </td>
        </tr>
    </table>
    <table class="table-detail" align="center">
        <tr>
            <th>序号</th>
            <th>主类</th>
            <th>子类</th>
            <th>名称</th>
            <th>品牌</th>
            <th>型号</th>
            <th >原Url</th>
            <th>状态</th>
            <th>操作</th>
            <th>弃用</th>
        </tr>
        <c:forEach items="${srm}" var="var" varStatus="s">
        <tr>
            <td nowrap="nowrap"><input type="checkbox" name="checkboxAll" id="checkbox_${var.id}" value="${var.id}" /> </td>
            <td>${var.goodstype}</td>
            <td>${var.goodstwotype}</td>
            <td>${var.goodsname}</td>
            <td>${var.goodsbrand}&nbsp;</td>
            <td>${var.goodsmodel}&nbsp;</td>
            <td ><a href="${var.url}" target="_blank">
                    ${fn:replace(var.url,'https://detail.1688.com/offer/', '')}
            </a></td>
            <td >
                <c:if test="${var.status==0}">未确认</c:if>
                <c:if test="${var.status==1}">已确认</c:if>
                <c:if test="${var.status==-1}">弃用</c:if>
            </td>
            <td>
                <a href="javascript:ajaxUpFgoodsStatus('${var.id}','1')">确定</a>
                <a href="<%=basePath%>fgoods/edit?id=${var.id}" target="_blank" >编辑</a>
            </td>
            <td>
                <a href="javascript:ajaxUpFgoodsStatus('${var.id}','-1')">弃用</a>
            </td>
        </tr>
        </c:forEach>
    </table>
</div>
<div style="overflow:hidden;margin:0 auto; width:1131px;">
    <input type="hidden" id="currentPage" name="currentPage" value="${SRModel.currentPage}">

    <ul style="float:right;">
        <li>当前第 ${SRModel.currentPage} 页/共 ${SRModel.totalPage} 页 每页
            <input type="text" id="showCount" name="showCount" value="${SRModel.showCount}" style="width:50px;"/> 条/共 ${SRModel.totalCount} 条</li>
        <li><a href="javascript:searchData(1);">首页</a></li>
        <li><a href="javascript:searchData(${SRModel.currentPage-1});">上一页</a></li>
        <li><a href="javascript:searchData(${SRModel.currentPage+1});">下一页</a></li>
        <li><a href="javascript:searchData(${SRModel.totalPage});">末页</a></li>
        <li>
            跳到第&nbsp;<input type="text" id="inputPage" name="inputPage" value="" style="width:50px;"/>
                  &nbsp;<a href="javascript:goPageIndex();">Go 确定</a>
        </li>
    </ul>
</div>
</form>
</body>
<script type="text/javascript">
    window.onload=function(){
        $("#status").val("${SRModel.status}")
    };

    function goPageIndex(){
        var inputPage = document.getElementById("inputPage").value;
        if(isNaN(inputPage) || inputPage==""){
            document.getElementById("inputPage").focus();
            alert("请输入数字!");
            return ;
        }
        if(inputPage>Number("${SRModel.totalPage}")){
            inputPage = ${SRModel.totalPage};
        }
        searchData(inputPage);
    }

    function searchData(currentPage){
        if(currentPage>Number("${SRModel.totalPage}")){
            currentPage = ${SRModel.totalPage};
        }
        document.getElementById("currentPage").value = currentPage;
        document.motoForm.submit();
    }


    function clearFrom(){
        document.getElementById("goodsname").value="";
        document.getElementById("goodstype").value="";
        document.getElementById("goodstwotype").value="";
        document.getElementById("status").value="";
    }


    function goEdit(id){
        var url = "<%=basePath%>fgoods/edit?id="+id;
        //window.location.href =url;
        winopen(url,800,600);
    }

    function winopen(url,width,height){
        var left = (screen.width/2) - width/2;
        var top = (screen.height/2) - height/2;
        var styleStr = 'toolbar=no,location=no,directories=auto,status=no,menubar=no,scrollbars=yes,resizable=yes,z-look=no,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
        window.open(url,"", styleStr);
    }


    // 批量确认
    function ajaxAllUpFgoodsStatus(){
        var spCodesTemp = "";
        $('input:checkbox[name=checkboxAll]:checked').each(function(i){
            if(0==i){
                spCodesTemp = $(this).val();
            }else{
                spCodesTemp += (","+$(this).val());
            }
        });
        if(spCodesTemp==""){
            layer.msg("请选择要确认项的复选框");
            return ;
        }
        //layer.msg(spCodesTemp);
        if(!confirm("是否将选中标志为[确认]操作?")){
            return ;
        }
        $.ajax({
            type:"POST",
            url:"<%=basePath%>ajax/upfgoods/all/status",
            data:{
                'ids' : spCodesTemp,
                'status' : "1",
                'tm':new Date().getTime()
            },
            dataType:'json',
            cache: false,
            async: false,
            success: function(data){
                if(data.code==0){
                    window.location.reload();
                }
            }, error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest.status+" | "+XMLHttpRequest.readyState+"|"+textStatus);
            }
        });
    }

    function ajaxUpFgoodsStatus(tid,status){
        if(status=="" || status == undefined || status == null){
            return ;
        }
        if(status==1 ||status=='1'){
            if(!confirm("标志为[确认]操作?")){
                return ;
            }
        }else if(status==-1 ||status=='-1'){
            if(!confirm("标志为[弃用]操作?")){
                return ;
            }
        }
        $.ajax({
            type:"POST",
            url:"<%=basePath%>ajax/upfgoods/status",
            data:{
                'id' : tid,
                'status' : status,
                'tm':new Date().getTime()
            },
            dataType:'json',
            cache: false,
            async: false,
            success: function(data){
                if(data.code==0){
                    window.location.reload();
                }
            }, error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest.status+" | "+XMLHttpRequest.readyState+"|"+textStatus);
            }
        });
    }


</script>
</html> 

